Hashing Graphs Trees Search Trees Indexing and Multiway Trees File Organization

Introduction

Graph ADT

Data Structure of Graph

Implementation of Graph

Graph traversals

Directed Graph

Planarity

Shortest path Dijkstra's algorithm

Shortest paths Floyd's algorithm

Minimal Spanning Trees

Travelling salesman and Vehicle Routing

Imagine you are responsible for supplying water, gas, or electricity to a group of houses connected by roads. Each road has a certain length, representing the distance between houses. Your goal is to minimize the total length of the pipes or cables needed to connect all the houses.


Consider the following scenario:


A
B C
D
E F

Weights:
A-B: 1
A-D: 5
B-C: 6
B-D: 3
C-D: 6
D-E: 6
D-F: 4
E-F: 2

We want to find the most efficient way to connect all houses using the shortest paths. This is where minimal spanning trees come into play.


What is a Minimal Spanning Tree?


A minimal spanning tree is a connected subgraph that includes all the vertices with the minimum possible total edge weight. In simpler terms, it's the most efficient way to connect all the houses with the shortest total length of pipes or cables.


Observations about Spanning Trees:


1. Avoid Circles: We don't want circular connections, as it's redundant and wasteful.
2. Tree Structure: A minimal spanning tree has a tree-like structure without cycles.


Greedy Algorithms:


A greedy algorithm makes decisions locally, choosing the best option at each step without considering the global impact. Two well-known greedy algorithms for finding minimal spanning trees are Prim's and Kruskal's.


Prim's Algorithm:


1. Start with an initial vertex (let's say A).
2. At each step, choose the shortest edge that connects a vertex in the existing tree to a vertex outside the tree.
3. Repeat until all vertices are included.


Let's walk through Prim's algorithm with our example:


A            A-B (1)
            /
B           D-A (5)
            |
D     +---- D-F (4)
            |
E           E-F (2)

Prim's algorithm starts with A and adds edges gradually, always choosing the shortest one. The resulting tree efficiently connects all houses with a total length of 12.


Kruskal’s Algorithm:


1. Start with an empty set of edges.
2. At each step, choose the shortest edge that doesn't create a cycle when added to the set.
3. Repeat until all vertices are included.


Let's see how Kruskal's algorithm works for our example:


A-B (1)
|
D-A (5)
|
D-F (4)
|
E-F (2)

Kruskal's algorithm sorts edges by weight and adds them in ascending order, ensuring the tree remains cycle-free. The resulting minimal spanning tree also has a total length of 12.


Which Algorithm to Choose?


Use Prim's algorithm if the graph is sparse (few edges compared to vertices).
Choose Kruskal's algorithm if the graph is highly connected (many edges, almost a complete graph).


In conclusion, whether you're planning utility connections or exploring graph theory, minimal spanning trees and their algorithms provide efficient solutions for connecting various points while minimizing overall length.

Minimal Spanning Tree


A Minimal Spanning Tree (MST) is a fundamental concept in graph theory. It's the smallest tree that connects all nodes in a graph with the minimum possible total edge weight. MSTs find applications in network design, clustering, and optimization, ensuring efficient and cost-effective connections between points.


Greedy Algorithms


Greedy Algorithms make decisions by choosing the best immediate option at each step, aiming for optimal results. Like a savvy decision-maker, they prioritize short-term gains to achieve overall efficiency. These algorithms thrive on seizing the moment, making choices that seem best at the time for a streamlined path to success.


Prim's Algorithm


Prim's Algorithm, a beacon of efficiency in graph theory, illuminates the shortest path to connect all nodes in a network. Like a diligent architect, it selects the lightest edges to construct a minimum spanning tree, ensuring optimal connectivity while minimizing cost. Elegant in its simplicity, it's a cornerstone of optimization.


Kruskal’s Algorithm


Kruskal's Algorithm, a captivating method in graph theory, swiftly finds the minimum spanning tree by greedily selecting edges with the lowest weight, ensuring connectivity while avoiding cycles. It dazzles with efficiency, making it a go-to choice for network optimization, routing, and clustering conundrums.